<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
   <button id="btn_1">开始计时</button>
   <input type="text" id="text">
   <button id="btn_2">停止计时</button>
 </body>
  <script>
      var $ = function(obj){
	     return document.getElementById(obj);
	  }
	  var time = 0;
	  var stop;
      window.onload = function(){
	     var btn_1 = $("btn_1");
		 var btn_2 = $("btn_2");
		 var text = $("text");
		 btn_1.onclick = function(){
		    stop = window.setInterval("text_start()",1000);
		 }
		 btn_2.onclick = text_stop;
	  }
	  //开始计数
	  function text_start(){
	      text.value = ++time;
	  }
	  function text_stop(){
	    clearInterval(stop);
	  }
  </script>
</html>
